#!/usr/bin/env python
# -*- coding:utf-8 -*-

from flask_restful import Resource,reqparse
from service.userService import UserService
from utils import commons
from flask import jsonify

class UserOtherResource(Resource):
	# 用户注册
	@classmethod
	def register(cls):
		parser = reqparse.RequestParser()
		parser.add_argument("UserName", location='form', required=False, help="UserName参数类型不正确或缺失")
		parser.add_argument("Account", location='form', required=False, help="Account参数类型不正确或缺失")
		parser.add_argument("Password", location='form', required=False, help="Password参数类型不正确或缺失")
		kwargs = parser.parse_args()
		kwargs = commons.put_remove_none(**kwargs)
		result = UserService.register(**kwargs)

		return jsonify(code=result['code'], message=result['message'], data=result['data'])

	# 用户登录
	@classmethod
	def login(cls):
		parser = reqparse.RequestParser()
		parser.add_argument("Account", location='form', required=False, help="Account参数类型不正确或缺失")
		parser.add_argument("Password", location='form', required=False, help="Password参数类型不正确或缺失")
		kwargs = parser.parse_args()
		kwargs = commons.put_remove_none(**kwargs)

		result = UserService.login(**kwargs)

		return jsonify(code=result['code'], message=result['message'], data=result['data'])
